<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="数据库表名:" prop="tableName">
          <el-input
            v-model="formModel.tableName"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="12">
            <el-button v-if="hasPermission('create_code')" type="primary" plain @click="createCode">生成代码</el-button>
            <el-button type="primary" plain @click="testWebservice">测试接口</el-button>
            <el-button type="primary" plain @click="downLoad">数据字典导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CodeList',
  components: {

  },
  props: {},
  data() {
    return {
      imageSrc:'',
      formModel: {
        tableName:''
      },
    }
  },
  computed: {},
  mounted() {

  },
  methods: {
    createCode() {
      if(!this.formModel.tableName){
        this.$message.warning('请输入数据库表名!')
        return false
      }
      const param = { ...this.formModel }
      const url = '/code/createCode'
      this.post(url, param).then(res => {
        this.$info("生成代码成功!")
      })
    },
    testWebservice() {
      const param = { ...this.formModel }
      const url = '/webservice/webservice'
      this.post(url, param).then(res => {
        this.$info("调用接口成功!")
      })
    },
    downLoad() {
      const url = '/export/dictionary'
      const param = {}
      this.postUseBlob(url, param).then(res => {
        const blob = new Blob([res], {
          type: "application/vnd.ms-excel"
        });
        let fileName = "MES新平台数据字典.xls";
        if ("download" in document.createElement("a")) {
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          navigator.msSaveBlob(blob, fileName);
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
